From 951f7019b304442519c93e1837a45c17db49899d Mon Sep 17 00:00:00 2001 From: "mjw@wray-m-3.hpl.hp.com" Date: Thu, 19 Aug 2004 11:58:11 +0000 Subject: [PATCH] bitkeeper revision 1.1159.1.86 (412495d3pSRY5XpdRb-xCxOKOJxElg) Rename xmdefaults to xmdefconfig. Rename other xm config examples. Change default script dir to /etc/xen/scripts. --- .rootkeys | 7 +- tools/examples/Makefile | 29 ++-- tools/examples/README | 136 +--------------- tools/examples/network | 18 ++- tools/examples/vifctl | 149 ------------------ tools/examples/{xmdefaults => xmdefconfig} | 2 +- .../{xmexample => xmdefconfig-example} | 0 .../{xmnetbsd-example => xmdefconfig-netbsd} | 0 tools/python/xen/xend/XendRoot.py | 2 +- tools/python/xen/xm/create.py | 130 ++++++++------- tools/python/xen/xm/help.py | 4 +- tools/python/xen/xm/opts.py | 87 ++++++---- 12 files changed, 168 insertions(+), 396 deletions(-) delete mode 100644 tools/examples/vifctl rename tools/examples/{xmdefaults => xmdefconfig} (98%) rename tools/examples/{xmexample => xmdefconfig-example} (100%) rename tools/examples/{xmnetbsd-example => xmdefconfig-netbsd} (100%) diff --git a/.rootkeys b/.rootkeys index ab4ce594ac..d7ca5387de 100644 --- a/.rootkeys +++ b/.rootkeys @@ -251,11 +251,10 @@ 405ff55dawQyCHFEnJ067ChPRoXBBA tools/examples/init.d/xend 40ee75a9xFz6S05sDKu-JCLqyVTkDA tools/examples/network 40ee75a967sxgcRY4Q7zXoVUaJ4flA tools/examples/vif-bridge -40e15b7edWEtBf_oe3eBwGKuh1dyzQ tools/examples/vifctl 40ee75a93cqxHp6MiYXxxwR5j2_8QQ tools/examples/xend-config.sxp -41090ec8Pj_bkgCBpg2W7WfmNkumEA tools/examples/xmdefaults -40cf2937oKlROYOJTN8GWwWM5AmjBg tools/examples/xmexample -40dfd40auJwNnb8NoiSnRkvZaaXkUg tools/examples/xmnetbsd-example +41090ec8Pj_bkgCBpg2W7WfmNkumEA tools/examples/xmdefconfig +40cf2937oKlROYOJTN8GWwWM5AmjBg tools/examples/xmdefconfig-example +40dfd40auJwNnb8NoiSnRkvZaaXkUg tools/examples/xmdefconfig-netbsd 3fbba6dbDfYvJSsw9500b4SZyUhxjQ tools/libxc/Makefile 3fbba6dc1uU7U3IFeF6A-XEOYF2MkQ tools/libxc/rpm.spec 3fbba6dcrNxtygEcgJYAJJ1gCQqfsA tools/libxc/xc.h diff --git a/tools/examples/Makefile b/tools/examples/Makefile index f7c3fd7420..0aa958f685 100644 --- a/tools/examples/Makefile +++ b/tools/examples/Makefile @@ -1,32 +1,37 @@ -INSTALL = $(wildcard *.py) +# Init scripts. +XEND_INITD = init.d/xend -INITD = init.d/xend +# Xen configuration dir and configs to go there. +XEN_CONFIG_DIR = /etc/xen +XEN_CONFIGS = xend-config.sxp +XEN_CONFIGS += xmdefconfig +XEN_CONFIGS += xmdefconfig-example +XEN_CONFIGS += xmdefconfig-netbsd -XEN_CONFIG_DIR = /etc/xen -XEN_CONFIGS = xmdefaults xmnetbsd xend-config.sxp - -XEN_SCRIPT_DIR = /etc/xen -XEN_SCRIPTS = vifctl network vif-bridge +# Xen script dir and scripts to go there. +XEN_SCRIPT_DIR = /etc/xen/scripts +XEN_SCRIPTS = network +XEN_SCRIPTS += vif-bridge all: install: all install-initd install-configs install-scripts install-initd: - mkdir -p $(prefix)/etc/init.d - install -m0755 $(INITD) $(prefix)/etc/init.d + install -d $(prefix)/etc/init.d + install -m0755 $(XEND_INITD) $(prefix)/etc/init.d install-configs: - mkdir -p $(prefix)$(XEN_CONFIG_DIR) - mkdir -p $(prefix)$(XEN_CONFIG_DIR)/auto + install -d $(prefix)$(XEN_CONFIG_DIR) + install -d $(prefix)$(XEN_CONFIG_DIR)/auto for i in $(XEN_CONFIGS); \ do [ -a $(prefix)/$(XEN_CONFIG_DIR)/$$i ] || \ install -m0644 $$i $(prefix)$(XEN_CONFIG_DIR); \ done install-scripts: - mkdir -p $(prefix)$(XEN_SCRIPT_DIR) + install -d $(prefix)$(XEN_SCRIPT_DIR) for i in $(XEN_SCRIPTS); \ do [ -a $(prefix)/$()/$$i ] || \ install -m0755 $$i $(prefix)$(XEN_SCRIPT_DIR); \ diff --git a/tools/examples/README b/tools/examples/README index 117f1091ef..43a4f48c08 100644 --- a/tools/examples/README +++ b/tools/examples/README @@ -1,138 +1,18 @@ -Xen Control Tools - Example Scripts +Xen Control Tools - Examples =================================== -This directory contains a set of example scripts for common Xen operations. +This directory contains example scripts and configurations for Xen. For many operations you will either be able to use these scripts directly, or incorporate code from them into your own scripts. -The Xc and xenctl.utils Python modules provide an API for accessing all this -functionality - and more - from your own Python programs. These libraries may -contain features for which there aren't yet example scripts written for... - If you write a useful script and would like to share it, please do send it (preferably with a little summary to go in this file) to so we can add it to this directory. -xc_dom_control.py - - general tool for controling running domains - Usage: xc_dom_control.py [command] - - stop [dom] -- pause a domain - start [dom] -- un-pause a domain - shutdown [dom] [[-w]] -- request a domain to shutdown (can specify 'all') - (optionally wait for complete shutdown) - destroy [dom] -- immediately terminate a domain - pincpu [dom] [cpu] -- pin a domain to the specified CPU - suspend [dom] [file] -- write domain's memory to a file and terminate - (resume by re-running xc_dom_create with -L option) - unwatch [dom] -- kill the auto-restart daemon for a domain - list -- print info about all domains - listvbds -- print info about all virtual block devs - cpu_bvtset [dom] [mcuadv] [warp] [warpl] [warpu] - -- set BVT scheduling parameters for domain - cpu_bvtslice [slice] -- set default BVT scheduler slice - cpu_atropos_set [dom] [period] [slice] [latency] [xtratime] - -- set Atropos scheduling parameters for domain - cpu_rrobin_slice [slice] -- set Round Robin scheduler slice - vif_stats [dom] [vif] -- get stats for a given network vif - vif_addip [dom] [vif] [ip] -- add an IP address to a given vif - vif_setsched [dom] [vif] [bytes] [usecs] -- rate limit vif bandwidth - vif_getsched [dom] [vif] -- print vif's scheduling parameters - vbd_add [dom] [uname] [dev] [mode] -- make disk/partition uname available to - domain as dev e.g. 'vbd_add 2 phy:sda3 hda1 w' - vbd_remove [dom] [dev] -- remove disk or partition attached as 'dev' - - -xc_dom_create.py - - This tool is used to create and start new domains. It reads defaults -from a file written in Python, having allowed variables to be set and -passed into the file. Further command line arguments allow the -defaults to be overridden. The defaults for each parameter are listed -in [] brackets. Arguments are as follows: - -Arguments to control the parsing of the defaults file: - -f config_file -- Use the specified defaults script. - Default: ['/etc/xc/defaults'] - -L state_file -- Load virtual machine memory state from state_file - -D foo=bar -- Set variable foo=bar before parsing config - E.g. '-D vmid=3;ip=1.2.3.4' - -h -- Print extended help message, including all arguments - -n -- Dry run only, don't actually create domain - -q -- Quiet - write output only to the system log - - -The config file 'defaults' requires the following variable to be defined: - vmid -- Numeric identifier for the new domain, used to calculate - the VM's IP address and root partition. E.g. -Dvmid=1 - - -Arguments to override current config read from 'defaults': - -k image -- Path to kernel image [''] - -r ramdisk -- Path to ramdisk (or empty) [''] - -b builder_fn -- Function to use to build domain [''] - -m mem_size -- Initial memory allocation in MB [0MB] - -N domain_name -- Set textual name of domain [''] - -a auto_restart -- Restart domain on exit, yes/no ['0'] - -e vbd_expert -- Saftey catch to avoid some disk accidents ['0'] - -d udisk,dev,rw -- Add disk, partition, or virtual disk to domain. E.g. to - make partion sda4 available to the domain as hda1 with - read-write access: '-b phy:sda4,hda1,rw' To add - multiple disks use multiple -d flags or seperate with ';' - Default: [''] - -i vfr_ipaddr -- Add IP address to the list which Xen will route to - the domain. Use multiple times to add more IP addrs. - Default: [''] - -Args to override the kernel command line, which is concatenated from these: - -I cmdline_ip -- Override 'ip=ipaddr:nfsserv:gateway:netmask::eth0:off' - Default: [''] - -R cmdline_root -- Override root device parameters. - Default: [''] - -E cmdline_extra -- Override extra kernel args and rc script env vars. - Default: [''] - - - -xc_vd_tool.py - - tool for manipulating virtual disks - Usage: xc_vd_tool command - - initalise [dev] [[ext_size]] - init. a physcial partition to store vd's - create [size] [[expiry]] - allocate a vd of specified size (and expiry) - delete [vdid] - delete a vd - import [filename] [[expiry]] - create a vd and populate w/ image from file - export [vdid] [filename] - copy vd's contents to a file - setexpiry [vdid] [[expiry]] - update the expiry time for a vd - list - list all the unexpired virtual disks - undelete [vdid] [[expiry]] - attempts to recover an expired vd - freespace - print out the amount of space in free pool - - notes: - vdid - the virtual disk's identity string - size - measured in MB - expiry - is the expiry time of the virtual disk in seconds from now - (0 = don't expire) - device - physical partition to 'format' to hold vd's. e.g. hda4 - ext_size - extent size (default 64MB) - - -xendomains -This is a Sys-V init script for RedHat systems. - - - Usage: xendomains {start|stop|status} - - start -- starts all the domains with config files in /etc/xc/auto/ - stop -- stops ALL running domains, waiting for them to shutdown cleanly - (if possible) before returning - status -- prints a list of the running domains, the same as - "xc_dom_control.py list" - -On a RedHat system it should be possible to issue commands to this -script using the "service" command and to configure if / when it is -run automatically, using the "chkconfig" command. - -xend -This is a Sys-V init script for RedHat systems, which can be used to -start the Xen Daemon (xend) at boot time. +network - default network setup script called by xend at startup. +vif-bridge - default virtual network interface setup script. +xend-config.sxp - default xend configuration file. +xmdefconfig - default configuration script for 'xm create'. +xmdefconfig-example - a more complex configuration script for 'xm create'. +xmdefconfig-netbsd - an 'xm create' configuration script for NetBSD domains. - - Usage: xend {start|stop|status|restart|reload} diff --git a/tools/examples/network b/tools/examples/network index bd736e1ba5..6574399089 100755 --- a/tools/examples/network +++ b/tools/examples/network @@ -1,10 +1,22 @@ #!/bin/sh #============================================================================ -# Example Xen network start/stop script. +# Default Xen network start/stop script. # Xend calls a network script when it starts. -# This is the default script. +# The script name to use is defined in /etc/xen/xend-config.sxp +# in the network-script field. # -# /etc/xen/network (start|stop|status) {VAR=VAL}* +# This script creates a bridge (default xen-br0), adds a device +# (default eth0) to it, copies the IP addresses from the device +# to the bridge and adjusts the routes accordingly. +# +# If all goes well, this should ensure that networking stays up. +# However, some configurations are upset by this, especially +# NFS roots. If the bridged setup does not meet your needs, +# configure a different script, for example using routing instead. +# +# Usage: +# +# network (start|stop|status) {VAR=VAL}* # # Vars: # diff --git a/tools/examples/vifctl b/tools/examples/vifctl deleted file mode 100644 index 11aac70fa2..0000000000 --- a/tools/examples/vifctl +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/python -# -*- mode: python; -*- -#============================================================================ -# Xen vif control script. Lives in /etc/xen/xend. -# -# vifctl init [bridge=] [interface=] -# -# Called when xend starts up. Default behaviour is to create -# and add to it, moving its IP address to and adjusting routes. -# -# vifctl (up|down) vif= mac= [bridge=] (ipaddr=)* -# -# Called when a vif is brought up or down. Default behaviour is to add -# the vif to on up and remove it from the bridge on down. -# If ipaddr is specified, iptables rules for the ip addresses are -# added on up and removed on down. The bridge a vif is added to can -# be set in the vm config. -# -# The default bridge is xen-br0. -# The default interface is eth0. -# -#============================================================================ - -import sys -import types - -from xen.util import Brctl - -from xen.xend import XendRoot -xroot = XendRoot.instance() - -class VifControl: - - prefix = 'vifctl_' - - DEFAULT_BRIDGE = 'xen-br0' - DEFAULT_INTERFACE = 'eth0' - - def __init__(self): - self.name = 'vifctl' - - def main(self, args): - #print self.name, args - if len(args) < 2: - usage(args) - self.name = args[0] - cmd = self.prefix + args[1] - meth = getattr(self, cmd, self.unknown) - meth(args[1:]) - - def usage(self, args, out=sys.stderr): - print >>out, 'Missing command, try \n%s help' % self.name - - def unknown(self, args, out=sys.stderr): - print >>out, 'Unknown command:', args[1] - self.help(out=out) - sys.exit(1) - - def help(self, out=sys.stdout): - print >>out, 'Commands are:', - for x in vars(self): - if x.startswith(prefix): - cmd = x[len(prefix):] - print >>out, cmd, - print >>out - - def getparams(self, d, args, req=[]): - """Parse args of the form 'key=val'. Valid keys are the ones - in the dict 'd' passed in. If entries in 'd' have list values the - values of the keys are appended. - - If 'req' is specified it is a list of required keys. - """ - for x in args: - (k, v) = x.split('=') - k = k.strip() - v = v.strip() - if k not in d: - print >>sys.stderr, 'Invalid parameter: ', k - sys.exit(1) - vold = d[k] - if isinstance(vold , types.ListType): - d[k] = vold + v - else: - d[k] = v - for x in req: - if not d[x]: - print >>sys.stderr, 'Missing parameter:', x - sys.exit(1) - return d - - def vifctl_help(self, args): - self.help() - - def default_bridge(self): - return xroot.get_config_value('bridge', self.DEFAULT_BRIDGE) - - def default_interface(self): - return xroot.get_config_value('interface', self.DEFAULT_INTERFACE) - - def vifctl_init(self, args): - """Entry point for 'vifctl init'. - """ - d = { 'bridge' : self.default_bridge(), - 'interface': self.default_interface() } - params = self.getparams(d, args[1:]) - interface = params['interface'] - bridge = params['bridge'] - # Create bridge 'bridge'. - Brctl.bridge_create(bridge) - # Reconfigure so that 'interface' is added to 'bridge', - # and 'bridge' has the IP address from 'interface'. - Brctl.reconfigure(interface, bridge) - - def vifparams(self, args): - d = { 'vif' : None, - 'mac' : None, - 'bridge': self.default_bridge(), - 'ipaddr': [] } - d = self.getparams(d, args, req=['vif', 'mac']) - return d - - def vifctl_up(self, args): - """Entry point for 'vifctl up'. - """ - params = self.vifparams(args[1:]) - # Add the vif to its bridge. - Brctl.vif_bridge_add(params) - if params['ipaddr']: - # Add iptables rules for the ip addresses. - vif = params['vif'] - for ipaddr in params['ipaddr']: - Brctl.vif_restrict_addr(vif, ipaddr) - - def vifctl_down(self, args): - """Entry point for 'vifctl down'. - """ - params = self.vifparams(args[1:]) - # Remove the vif from its bridge. - Brctl.vif_bridge_rem(params) - if params['ipaddr']: - # Remove iptables rules for the ip addresses. - vif = params['vif'] - for ip in params['ipaddr']: - Brctl.vif_restrict_addr(vif, ip, delete=1) - - -if __name__ == "__main__": - VifControl().main(sys.argv) diff --git a/tools/examples/xmdefaults b/tools/examples/xmdefconfig similarity index 98% rename from tools/examples/xmdefaults rename to tools/examples/xmdefconfig index 0b7c5b2230..b297d1d846 100644 --- a/tools/examples/xmdefaults +++ b/tools/examples/xmdefconfig @@ -1,6 +1,6 @@ # -*- mode: python; -*- #============================================================================ -# Python defaults setup for 'xm create'. +# Python configuration setup for 'xm create'. # This script sets the parameters used when a domain is created using 'xm create'. # You use a separate script for each domain you want to create, or # you can set the parameters for the domain on the xm command line. diff --git a/tools/examples/xmexample b/tools/examples/xmdefconfig-example similarity index 100% rename from tools/examples/xmexample rename to tools/examples/xmdefconfig-example diff --git a/tools/examples/xmnetbsd-example b/tools/examples/xmdefconfig-netbsd similarity index 100% rename from tools/examples/xmnetbsd-example rename to tools/examples/xmdefconfig-netbsd diff --git a/tools/python/xen/xend/XendRoot.py b/tools/python/xen/xend/XendRoot.py index 9f23d1c686..12e13a2756 100644 --- a/tools/python/xen/xend/XendRoot.py +++ b/tools/python/xen/xend/XendRoot.py @@ -44,7 +44,7 @@ class XendRoot: config_var = "XEND_CONFIG" """Where network control scripts live.""" - network_script_dir = "/etc/xen" + network_script_dir = "/etc/xen/scripts" logfile_default = "/var/log/xend.log" diff --git a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py index dad9c8ee34..01ab1e8a12 100644 --- a/tools/python/xen/xm/create.py +++ b/tools/python/xen/xm/create.py @@ -20,48 +20,47 @@ Create a domain. Domain creation parameters can be set by command-line switches, from a python configuration script or an SXP config file. See documentation -for --defaults, --config. Configuration variables can be set using +for --defconfig, --config. Configuration variables can be set using VAR=VAL on the command line. For example vmid=3 sets vmid to 3. """) gopts.opt('help', short='h', - fn=set_true, default=0, - use="Print this help.") + fn=set_true, default=0, + use="Print this help.") gopts.opt('help_config', fn=set_true, default=0, - use="Print help for configuration file.") + use="Print help for the configuration script.") gopts.opt('quiet', short='q', - fn=set_true, default=0, - use="Quiet.") + fn=set_true, default=0, + use="Quiet.") gopts.opt('path', val='PATH', - fn=set_value, default='.:/etc/xen', - use="Search path for default scripts.") - -gopts.opt('defaults', short='f', val='FILE', - fn=set_value, default='xmdefaults', - use="""Use the given Python defaults script. -The defaults script is loaded after arguments have been processed. -Each command-line option sets a configuration variable named after -its long option name, and these variables are placed in the -environment of the script before it is loaded. -Variables for options that may be repeated have list values. -Other variables can be set using VAR=VAL on the command line. - -After the script is loaded, option values that were not set on the -command line are replaced by the values set in the script. -""") + fn=set_value, default='.:/etc/xen', + use="""Search path for configuration scripts. + The value of PATH is a colon-separated directory list.""") + +gopts.opt('defconfig', short='f', val='FILE', + fn=set_value, default='xmdefconfig', + use="""Use the given Python configuration script. + The configuration script is loaded after arguments have been processed. + Each command-line option sets a configuration variable named after + its long option name, and these variables are placed in the + environment of the script before it is loaded. + Variables for options that may be repeated have list values. + Other variables can be set using VAR=VAL on the command line. + + After the script is loaded, option values that were not set on the + command line are replaced by the values set in the script.""") gopts.opt('config', short='F', val='FILE', - fn=set_value, default=None, - use="""Domain configuration to use (SXP). -SXP is the underlying configuration format used by Xen. -SXP configs can be hand-written or generated from Python defaults -scripts, using the -n (dryrun) option to print the config. -""") + fn=set_value, default=None, + use="""Domain configuration to use (SXP). + SXP is the underlying configuration format used by Xen. + SXP configurations can be hand-written or generated from Python configuration + scripts, using the -n (dryrun) option to print the configuration.""") gopts.opt('load', short='L', val='FILE', fn=set_value, default=None, @@ -69,9 +68,8 @@ gopts.opt('load', short='L', val='FILE', gopts.opt('dryrun', short='n', fn=set_true, default=0, - use="""Dry run - print the config but don't create the domain. -The defaults file is loaded and the SXP configuration is created and printed. -""") + use="""Dry run - print the configuration but don't create the domain. + Loads the configuration script, creates the SXP configuration and prints it.""") gopts.opt('paused', short='p', fn=set_true, default=0, @@ -83,7 +81,7 @@ gopts.opt('console_autoconnect', short='c', gopts.var('name', val='NAME', fn=set_value, default=None, - use="Domain name.") + use="Domain name. Must be unique.") gopts.var('kernel', val='FILE', fn=set_value, default=None, @@ -98,13 +96,17 @@ gopts.var('builder', val='FUNCTION', use="Function to use to build the domain.") gopts.var('memory', val='MEMORY', - fn=set_value, default=128, + fn=set_int, default=128, use="Domain memory in MB.") +gopts.var('cpu', val='CPU', + fn=set_int, default=None, + use="CPU to run the domain on.") + gopts.var('cpu_weight', val='WEIGHT', - fn=set_float, default=1, - use="""Set the new domain's cpu weight. WEIGHT is a float that controls the -domain's share of the cpu.""") + fn=set_float, default=None, + use="""Set the new domain's cpu weight. + WEIGHT is a float that controls the domain's share of the cpu.""") gopts.var('console', val='PORT', fn=set_int, default=None, @@ -113,10 +115,9 @@ gopts.var('console', val='PORT', gopts.var('restart', val='onreboot|always|never', fn=set_value, default=None, use="""Whether the domain should be restarted on exit. - - onreboot: restart on exit with shutdown code reboot - - always: always restart on exit, ignore exit code - - never: never restart on exit, ignore exit code - """) + - onreboot: restart on exit with shutdown code reboot + - always: always restart on exit, ignore exit code + - never: never restart on exit, ignore exit code""") gopts.var('blkif', val='no|yes', fn=set_bool, default=0, @@ -129,18 +130,16 @@ gopts.var('netif', val='no|yes', gopts.var('disk', val='phy:DEV,VDEV,MODE[,DOM]', fn=append_value, default=[], use="""Add a disk device to a domain. The physical device is DEV, - which is exported to the domain as VDEV. The disk is read-only if MODE - is 'r', read-write if MODE is 'w'. If DOM is specified it defines the - backend driver domain to use for the disk. - The option may be repeated to add more than one disk. - """) + which is exported to the domain as VDEV. The disk is read-only if MODE + is 'r', read-write if MODE is 'w'. If DOM is specified it defines the + backend driver domain to use for the disk. + The option may be repeated to add more than one disk.""") gopts.var('pci', val='BUS,DEV,FUNC', fn=append_value, default=[], use="""Add a PCI device to a domain, using given params (in hex). For example '-pci c0,02,1a'. - The option may be repeated to add more than one pci device. - """) + The option may be repeated to add more than one pci device.""") gopts.var('ipaddr', val="IPADDR", fn=append_value, default=[], @@ -149,27 +148,25 @@ gopts.var('ipaddr', val="IPADDR", gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM", fn=append_value, default=[], use="""Add a network interface with the given MAC address and bridge. - The vif is configured by calling the given configuration script. - If mac is not specified a random MAC address is used. - If bridge is not specified the default bridge is used. - If script is not specified the default script is used. - If backend is not specified the default backend driver domain is used. - This option may be repeated to add more than one vif. - Specifying vifs will increase the number of interfaces as needed. - """) + The vif is configured by calling the given configuration script. + If mac is not specified a random MAC address is used. + If bridge is not specified the default bridge is used. + If script is not specified the default script is used. + If backend is not specified the default backend driver domain is used. + This option may be repeated to add more than one vif. + Specifying vifs will increase the number of interfaces as needed.""") gopts.var('nics', val="NUM", fn=set_int, default=1, use="""Set the number of network interfaces. - Use the vif option to define interface parameters, otherwise - defaults are used. Specifying vifs will increase the - number of interfaces as needed. - """) + Use the vif option to define interface parameters, otherwise + defaults are used. Specifying vifs will increase the + number of interfaces as needed.""") gopts.var('root', val='DEVICE', fn=set_value, default='', use="""Set the root= parameter on the kernel command line. - Use a device, e.g. /dev/sda1, or /dev/nfs for NFS root.""") + Use a device, e.g. /dev/sda1, or /dev/nfs for NFS root.""") gopts.var('extra', val="ARGS", fn=set_value, default='', @@ -261,7 +258,7 @@ def randomMAC(): The remaining 3 fields are random, with the first bit of the first random field set 0. - returns MAC address string + @return: MAC address string """ mac = [ 0xaa, 0x00, 0x00, random.randint(0x00, 0x7f), @@ -312,10 +309,11 @@ def make_config(vals): config = ['vm', ['name', vals.name ], - ['memory', vals.memory ], - ['cpu_weight', vals.cpu_weight] ] - if vals.cpu: + ['memory', vals.memory ]] + if vals.cpu is not None: config.append(['cpu', vals.cpu]) + if vals.cpu_weight is not None: + config.append(['cpu_weight', vals.cpu_weight]) if vals.blkif: config.append(['backend', ['blkif']]) if vals.netif: @@ -445,7 +443,7 @@ def main(argv): if opts.vals.help: opts.usage() if opts.vals.help or opts.vals.help_config: - opts.load_defaults(help=1) + opts.load_defconfig(help=1) if opts.vals.help or opts.vals.help_config: return # Process remaining args as config variables. @@ -456,7 +454,7 @@ def main(argv): if opts.vals.config: config = opts.vals.config else: - opts.load_defaults() + opts.load_defconfig() preprocess(opts, opts.vals) config = make_config(opts.vals) if opts.vals.dryrun: diff --git a/tools/python/xen/xm/help.py b/tools/python/xen/xm/help.py index 88df4412c0..8efaf2946a 100644 --- a/tools/python/xen/xm/help.py +++ b/tools/python/xen/xm/help.py @@ -1,6 +1,6 @@ # Copyright (C) 2004 Mike Wray -"""Variable definition and help support for Python defaults files. +"""Variable definition and help support for Python defconfig files. """ import sys @@ -12,7 +12,7 @@ class Vars: def __init__(self, name, help, env): """Create a variable set. - name name of the defaults file + name name of the defconfig file help help flag env local environment """ diff --git a/tools/python/xen/xm/opts.py b/tools/python/xen/xm/opts.py index a46ab3c1f0..b206d6ce5a 100644 --- a/tools/python/xen/xm/opts.py +++ b/tools/python/xen/xm/opts.py @@ -88,19 +88,31 @@ class Opt: else: return None - def show(self): - sep = '' + def format(self, str, start=' ', out=sys.stdout): + """Print a string, with consistent indentation at the start of lines. + """ + lines = str.split('\n') + for l in lines: + l = l.strip() + if start: + out.write(start) + out.write(l) + out.write('\n') + + def show(self, out=sys.stdout): + sep = ' ' for x in self.optkeys: - print sep, x, - sep = ',' + out.write(sep) + out.write(x) + sep = ', ' if self.val: - print self.val, - print + out.write(' ') + out.write(self.val) + out.write('\n') if self.use: - print '\t', - print self.use + self.format(self.use, out=out); if self.val: - print '\tDefault', self.default or 'None' + self.format('Default ' + str(self.default or 'None'), out=out) def specify(self, k, v): """Specify the option. Called when the option is set @@ -153,14 +165,12 @@ class OptVar(Opt): def long_opt(self): return None - def show(self): - print '%s=%s' %(self.optkeys[0], self.val) - print + def show(self, out=sys.stdout): + print >>out, ' %s=%s' % (self.optkeys[0], self.val) if self.use: - print '\t', - print self.use + self.format(self.use, out=out); if self.val: - print '\tDefault', self.default or 'None' + self.format('Default ' + str(self.default or 'None'), out=out) class OptVals: """Class to hold option values. @@ -328,29 +338,48 @@ class Opts: def usage(self): print 'Usage: ', self.argv[0], self.use or 'OPTIONS' + print for opt in self.options: - print opt.show() + print + if self.options: + print - def load_defaults(self, help=0): - """Load a defaults script. Assumes these options set: + def var_usage(self): + if self.vars: + print 'The defconfig defines the following variables:' + for var in self.vars: + var.show() + print + print + + def config_usage(self): + if self.imports: + print 'The following are automically imported:' + for x in self.imports: + print ' ', x + print + self.var_usage() + + def load_defconfig(self, help=0): + """Load a defconfig script. Assumes these options set: 'path' search path - 'default' script name + 'defconfig' script name """ for x in [ '' ] + self.vals.path.split(':'): if x: - p = os.path.join(x, self.vals.defaults) + p = os.path.join(x, self.vals.defconfig) else: - p = self.vals.defaults + p = self.vals.defconfig if os.path.exists(p): - self.info('Using config file %s' % p) + self.info('Using defconfig file %s.' % p) self.load(p, help) break else: - self.err("Cannot open defaults file %s" % self.vals.defaults) + self.err("Cannot open defconfig file %s" % self.vals.defconfig) - def load(self, defaults, help): - """Load a defaults file. Local variables in the file + def load(self, defconfig, help): + """Load a defconfig file. Local variables in the file are used to set options with the same names. Variables are not used to set options that are already specified. """ @@ -363,19 +392,17 @@ class Opts: locals.update(self.vars) cmd = '\n'.join(self.imports + [ "from xen.xm.help import Vars", - "xm_file = '%s'" % defaults, + "xm_file = '%s'" % defconfig, "xm_help = %d" % help, "xm_vars = Vars(xm_file, xm_help, locals())" ]) exec cmd in globals, locals try: - execfile(defaults, globals, locals) + execfile(defconfig, globals, locals) except: if not help: raise if help: - print 'The following imports are done automatically:' - for x in self.imports: - print x + self.config_usage() return # Extract the values set by the script and set the corresponding # options, if not set on the command line. -- 2.30.2